package com.fangmu.transferdata;

import android.content.Context;
import android.widget.Toast;

import com.fangmu.transferdata.MainConstract;
import com.fangmu.transferdata.utils.UsbHelper;
import com.github.mjdev.libaums.UsbMassStorageDevice;
import com.github.mjdev.libaums.fs.UsbFile;

import java.util.ArrayList;

/**
 * @author created by lyl
 * @data 2022/4/6.
 * @description
 */
public class MainPresenter implements MainConstract.Presenter{
    private Context context;
    private MainConstract.View mView;

    public MainPresenter(Context context, MainConstract.View mView) {
        this.context = context;
        this.mView = mView;
    }


    @Override
    public void getUDiskList(UsbMassStorageDevice[] deviceList, UsbHelper usbHelper) {
        if (deviceList.length == 0) {
            Toast.makeText(context, "读取U盘列表失败，请检查是否插入U盘", Toast.LENGTH_SHORT).show();
        }else {
            UsbMassStorageDevice device = deviceList[0];
            ArrayList<UsbFile> usbFiles = usbHelper.readDevice(device);
            if (usbFiles.size() == 0) {
                mView.setUDiskList(usbFiles);
                mView.setUDiskStatus("读取失败，请重新点击按钮尝试");
            }else {
                mView.setUDiskStatus("读取成功!!");
                mView.setUDiskList(usbFiles);
            }
        }
    }

    @Override
    public boolean judgeDataLength(String msg) {
        if (msg == null) {
            return false;
        }else {
            return true;
        }
    }
}
